package com.orangelife.mobile.propertyOld.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.widget.ScrollListView;

import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 账单明细的适配器
 * Created by ${shz} on 2015/11/15.
 */
public class PropertyBillDetailOldOrderInfoAdapter<T> extends FatherAdapter<T> {
    private Context mContext;
    private List<Map<String, Object>> mList;

    public PropertyBillDetailOldOrderInfoAdapter(Context mContext, List<Map<String, Object>> list) {
        this.mContext = mContext;
        this.mList = list;
    }

    @Override
    public BaseAdapter setList(List<T> list) {
        if(mList!=null){
            mList.clear();
            mList.addAll((List<Map<String, Object>>) list);
        }
        return this;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_property_bill_detail_old, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Map<String, Object> map = mList.get(position);
        viewHolder.tvCostName.setText(String.valueOf(map.get("name")));
        viewHolder.tvCostContent.setText(String.valueOf(map.get("value")));
        if (map.get("subitem") != null) {
            List<Map<String, Object>>itemlist = (List<Map<String, Object>>) map.get("subitem");
            if (itemlist.size() != 0) {
                PropertyBillDetailOldBaseInfoAdapter itemAdapter = new PropertyBillDetailOldBaseInfoAdapter(mContext, itemlist);
                viewHolder.lvItem.setAdapter(itemAdapter);
            }
        }
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tvCostName)
        TextView tvCostName;
        @Bind(R.id.tvSymbol)
        TextView tvSymbol;
        @Bind(R.id.tvCostContent)
        TextView tvCostContent;
        @Bind(R.id.lvItem)
        ScrollListView lvItem;
        @Bind(R.id.rlItem)
        LinearLayout rlItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
